package threadcreate01;

public class threadmethod {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread() {
            @Override
            public void run() {
                int i = 0;
                while (i < 1000) {
                    System.out.println("线程1：" + i++);
                }
            }
        };

        //1.设置线程的名字
        thread.setName("张大力的线程1");
        //2.获取线程的名字
        System.out.println(thread.getName());
        //3.设置线程的优先级
        thread.setPriority(Thread.MAX_PRIORITY);
        thread.start();
        //4.获取当前正在运行的线程的名字
        Thread thread1 = Thread.currentThread();
        System.out.println(thread1.getName());

        //5让当前线程进行一个休眠
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //6.让当前线程让出执行状态，重新进行一个线程调度
        Thread.yield();

        //7.判断当前线程是否已经停止
        System.out.println(thread.isAlive());

        //8.让当前线程等待另一个线程运行结束,有点类似于插队，让线程1先运行完，再运行线程2
        thread.join();
        //9.获取线程的优先级
        System.out.println(thread.getPriority());
        //10.设置守护线程
        thread.setDaemon(true);
        //11.查看线程是否为守护线程
        System.out.println(thread.isDaemon());
    }
}
